package a51qindian.com.comprehensive.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.li.interfaces.OnItemClickListener;
import com.li.widget.DoubleTextView;

import java.util.List;

import a51qindian.com.comprehensive.R;
import a51qindian.com.comprehensive.fragment.AdvVerifyFragment;
import a51qindian.com.comprehensive.model.AdvInfo;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: Li
 * Date: 2017/9/22 0022
 * Description: 置顶广告适配器
 */

public class AdvVerifyAdapter extends RecyclerView.Adapter<AdvVerifyAdapter.AdvVerifyHolder> {


    private LayoutInflater mInflater;
    private String mType;
    private List<AdvInfo> mAdvInfoList;

    public AdvVerifyAdapter(Context context, String type) {
        mInflater = LayoutInflater.from(context);
        mType = type;
    }


    private OnItemClickListener mItemClickListener;

    @Override
    public AdvVerifyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_adv_verify, parent, false);
        final AdvVerifyHolder holder = new AdvVerifyHolder(view);
        if (mType.equals(AdvVerifyFragment.ADV_VERIFY_UNFINISHED)) {
            holder.mTxtDeal.setVisibility(View.VISIBLE);
            if (mItemClickListener != null) {
                holder.mTxtDeal.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mItemClickListener.onItemClick(v, holder.getLayoutPosition());
                    }
                });
            }
        } else {
            holder.mTxtDeal.setVisibility(View.GONE);
        }
        return holder;
    }

    @Override
    public void onBindViewHolder(AdvVerifyHolder holder, int position) {
        AdvInfo advInfo = mAdvInfoList.get(position);
        holder.mTxtShopName.setTxtRight(advInfo.getShop_name());
        holder.mTxtPhone.setTxtRight(advInfo.getMobile());
        holder.mTxtAddress.setTxtRight(advInfo.getAddress());
        String status="";
        switch (advInfo.getStatus()) {
            case "0":
                status="申请中";
                break;
            case "1":
                status="申请成功";

                break;
            case "2":
                status="申请失败";
                break;
        }
        holder.mTxtStatus.setTxtRight(status);
    }

    @Override
    public int getItemCount() {
        return mAdvInfoList == null ? 0 : mAdvInfoList.size();
    }

    public void setAdvInfoList(List<AdvInfo> advInfoList) {
        mAdvInfoList = advInfoList;
        notifyDataSetChanged();
    }

    public void setItemClickListener(OnItemClickListener itemClickListener) {
        mItemClickListener = itemClickListener;
    }

    static class AdvVerifyHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_shop_name)
        DoubleTextView mTxtShopName;
        @BindView(R.id.txt_phone)
        DoubleTextView mTxtPhone;
        @BindView(R.id.txt_deal)
        TextView mTxtDeal;
        @BindView(R.id.txt_address)
        DoubleTextView mTxtAddress;
        @BindView(R.id.txt_status)
        DoubleTextView mTxtStatus;

        public AdvVerifyHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
